package org.itboys.weixin.util.test;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by hasee on 2017/7/18.
 */
public class test {
    public static void main(String[] args) {
        Map<String,String> state =getParam2("oa=999|oldUrl=/yefu/weixin/favorite/member?memberId=72|degree=_1");
        System.out.println(state.get("oa"));
        System.out.println(state.get("degree"));
        System.out.println(state.get("oldUrl"));
        for (String in : state.keySet()) {
                       //map.keySet()返回的是所有key的值
                        String str = state.get(in);//得到每个key多对用value的值
                        System.out.println("key="+in + ",value=" + str);

                     }
    }
    public static Map<String, String> getParam(String strUrlParam)
    {
        Map<String, String> mapRequest = new HashMap<String, String>();
        String[] arrSplit=null;
//    	String strUrlParam=TruncateUrlPage(URL);
//    	if(strUrlParam==null)
//    	{
//    		return null;
//    	}
        //每个键值为一组
        arrSplit=strUrlParam.split("[|]");
        for(String strSplit:arrSplit)
        {
            String[] arrSplitEqual=null;
            arrSplitEqual= strSplit.split("[=]");

            //解析出键值
            if(arrSplitEqual.length>1)
            {
                //正确解析
                mapRequest.put(arrSplitEqual[0], arrSplitEqual[1]);

            }
            else
            {
                if(arrSplitEqual[0]!="")
                {
                    //只有参数没有值，不加入
                    mapRequest.put(arrSplitEqual[0], "");
                }
            }
        }
        return mapRequest;
    }

    public static Map<String, String> getParam2(String strUrlParam)
    {
        Map<String, String> mapRequest = new HashMap<String, String>();
        //每一竖线代表一组数据。a=1|b=3
        String[] arrSplit=strUrlParam.split("[|]");
        for(String strSplit:arrSplit) {
            int index=strSplit.indexOf("=");
            String key=strSplit.substring(0,index);
            String vale=strSplit.substring(index,strSplit.length());
            if(key!=null&&key!=""){
                mapRequest.put(key,vale);
            }
        }
        return mapRequest;
    }
}
